package com.wh.concurrent.Daemon;

import java.io.IOException;

public class DaemonThreadTest implements Runnable {

	public static void main(String[] args) {
		Thread thread = new Thread(new DaemonThreadTest(), "普通线程");
		thread.setDaemon(true);
		thread.start();
		System.out.println("isDaemon = " + thread.isDaemon());
		try {
			System.in.read(); // 接受输入，使程序在此停顿，一旦接收到用户输入，main线程结束，守护线程自动结束
		} catch (IOException ex) {
			ex.printStackTrace();
		}
	}

	@Override
	public void run() {
		for (int i = 0; i < 10; i++) {
			System.out.println("打印i的值为:" + i);
			try {
				Thread.currentThread().sleep(200);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
}
